package com.jason.www.pubsub.service.impl;

import com.jason.www.pubsub.core.CustomEventPublisher;
import com.jason.www.pubsub.event.SendEmailEvent;
import com.jason.www.pubsub.service.ISendEmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class SendEmailServiceImpl implements ISendEmailService {
    protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
    private Integer num = 1;

    @Override
    public void emailRemind() {
        String id = genGoodsId();
        CustomEventPublisher.publish(new SendEmailEvent("JasonChoi").setMsg("商品到货提醒，商品ID为："+ id + ",执行编号:" + num++));
    }

    private static String genGoodsId() {
        int num = (int)(Math.random()*99999999)+0;//构建一个八位数的商品ID
        StringBuffer ss = new StringBuffer().append(num);
        while (ss.length() !=8){
            ss.insert(0,"0");
        }
        return ss.toString();
    }

}
